﻿using System.Windows.Controls;
using System.Windows.Input;
using WWLauncher.Constant;
using WWLauncher.Util;
using WWLauncher.ViewModel;

namespace WWLauncher.View.UserControls.SystemItem
{
    /// <summary>
    /// SystemItem.xaml 的交互逻辑
    /// </summary>
    public partial class SystemItem : UserControl
    {
        public SystemItem()
        {
            InitializeComponent();
        }
        private void Icon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var thisInfo = (sender as StackPanel)?.Tag as IconViewModel;
            var mainViewModel = MainViewModel.Instance();
            MenuViewModel menuInfo = mainViewModel.MenuList[mainViewModel.SelectedMenuIndex];

            string startArg = thisInfo.StartArg;
            IconInfo iconInfo;
            if (Constants.SystemIcons.ContainsKey(startArg))
            {
                //系统项
                iconInfo = new IconInfo
                {
                    Name = thisInfo.Name,
                    TargetPath = thisInfo.TargetPath,
                    StartArg = thisInfo.StartArg,
                    BitmapImage = thisInfo.BitmapImage
                };
            }
            else
            {
                iconInfo = CommonCode.GetIconInfoByPath(thisInfo.LnkPath).To();
            }
            menuInfo.IconList.Add(iconInfo);
            ConfigUtil.SaveAppData();
        }
    }
}
